import logging
import sys
import datetime
"""
  日志方法
"""

def get_loggers(log_name):
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)

    # StreamHandler
    stream_handler = logging.StreamHandler(sys.stdout)
    stream_handler.setLevel(level=logging.DEBUG)
    logger.addHandler(stream_handler)

    # FileHandler
    file_handler = logging.FileHandler(log_name, encoding='utf-8')
    file_handler.setLevel(level=logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)
    return logger


# 调用日志方法
log = get_loggers(f'F:/PycharmProjects/wx9afood/logger/api_test_{datetime.datetime.now().strftime("%Y-%m-%d")}.log')
